package com.ruoyi.web.controller.exam;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.QtExam;
import com.ruoyi.exam.service.IQtExamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷管理Controller
 * 
 * @author zqq
 * @date 2021-11-18
 */
@RestController
@RequestMapping("/exam/exam")
public class QtExamController extends BaseController
{
    @Autowired
    private IQtExamService qtExamService;

    /**
     * 查询试卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('exam:exam:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtExam qtExam)
    {
        startPage();
        List<QtExam> list = qtExamService.selectQtExamList(qtExam);
        return getDataTable(list);
    }

    /**
     * 导出试卷管理列表
     */
    @PreAuthorize("@ss.hasPermi('exam:exam:export')")
    @Log(title = "试卷管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtExam qtExam)
    {
        List<QtExam> list = qtExamService.selectQtExamList(qtExam);
        ExcelUtil<QtExam> util = new ExcelUtil<QtExam>(QtExam.class);
        return util.exportExcel(list, "试卷管理数据");
    }

    /**
     * 获取试卷管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:exam:query')")
    @GetMapping(value = "/{examId}")
    public AjaxResult getInfo(@PathVariable("examId") String examId)
    {
        return AjaxResult.success(qtExamService.selectQtExamByExamId(examId));
    }

    /**
     * 新增试卷管理
     */
    @PreAuthorize("@ss.hasPermi('exam:exam:add')")
    @Log(title = "试卷管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtExam qtExam)
    {
        LoginUser user = getLoginUser();
        qtExam.setUserId(user.getUserId().toString());
        return toAjax(qtExamService.insertQtExam(qtExam));
    }

    /**
     * 修改试卷管理
     */
    @PreAuthorize("@ss.hasPermi('exam:exam:edit')")
    @Log(title = "试卷管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtExam qtExam)
    {
        return toAjax(qtExamService.updateQtExam(qtExam));
    }

    /**
     * 删除试卷管理
     */
    @PreAuthorize("@ss.hasPermi('exam:exam:remove')")
    @Log(title = "试卷管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable String[] examIds)
    {
        return toAjax(qtExamService.deleteQtExamByExamIds(examIds));
    }
}
